<?php
ob_start();

include_once 'inc/global.php';
include_once 'inc/queryhelper.php';

if (strlen(session_id()) < 1)
    session_start();

if (!isset($_SESSION['tid']))
    $_SESSION['tid'] = '';

$tid = $_GET['t'];// $_SESSION['tid'];
$tablename = $tables[$tid]['t'];

include 'inc/conn.php';
switch ($tid) {
    case 1: //city
        $city = $_REQUEST['city'];
        $sql = "insert into $tablename(city) values('$city')";
        break;
    case 2: //partner
        $partnername    = $_REQUEST['partnername'];
        $street1        = $_REQUEST['street1'];
        $city           = $_REQUEST['city'];
        $zip            = $_REQUEST['zip'];
        $phone1         = $_REQUEST['phone1'];
        $email          = $_REQUEST['email'];
        $cityname       = $_REQUEST['city']; //getFieldValue("ats_city", "city", "id", "'$city'");
        
        $sql = "insert into $tablename (partnername,street1,city, cityname,zipcode,phone1,email)
                values('$partnername','$street1','$city','$cityname','$zip','$phone1','$email')";
        break;
    case 3:  //package
        $title = $_REQUEST['title'];
        $short_title = $_REQUEST['short_title'];
        $cityid = $_REQUEST['cityid'];
        $monthstart = $_REQUEST['monthstart'];
        $yearstart = $_REQUEST['yearstart'];
        $monthend = $_REQUEST['monthend'];
        $yearend = $_REQUEST['yearend'];
        $currency = $_REQUEST['currency'];
        $currency = $_REQUEST['currency'];
        $pricestart = $_REQUEST['pricestart'];
        $dest_id = $_REQUEST['dest_id'];
        $cat_id = $_REQUEST['cat_id'];
        $isspecialoffer = $_REQUEST['isspecialoffer'];
        $ov_title = $_REQUEST['ov_title'];
        $ov_period = $_REQUEST['ov_period'];
        $ov_bonus = $_REQUEST['ov_bonus'];
        $ov_highlight = $_REQUEST['ov_highlight'];
        $ov_notice = $_REQUEST['ov_notice'];
        $da_pricelabel = $_REQUEST['da_pricelabel'];
        $da_depdates = $_REQUEST['da_depdates'];
        $da_extraprice = $_REQUEST['da_extraprice'];
        $da_pricetable = $_REQUEST['da_pricetable'];
        $tr_embassyid = $_REQUEST['tr_embassyid'];
//        $tr_embaddress = $_REQUEST['tr_embaddress'];
//        $tr_embphone = $_REQUEST['tr_embphone'];
//        $tr_embfax = $_REQUEST['tr_embfax'];
//        $tr_requirement = $_REQUEST['tr_requirement'];
//        $tr_notes = $_REQUEST['tr_notes'];
//        $tr_visaprices = $_REQUEST['tr_visaprices'];
        $pdf_attachment = $_REQUEST['pdf_attachment'];
        $featured = $_REQUEST['featured'];
        
        if ($tr_embassyid == '') $tr_embassyid = -1;

        $sql = "INSERT INTO
                  ats_package(
                    title,monthstart,monthend,yearstart,yearend,currency,pricestart,dest_id,cat_id,isspecialoffer,ov_title,ov_period,ov_bonus,ov_highlight,ov_notice,da_depdate,da_pricelabel,da_extraprice,da_pricetable,tr_embassyid,cityid,short_title,featured
                    )
                VALUES(
                    '$title','$monthstart','$monthend','$yearstart','$yearend','$currency','$pricestart','$dest_id','$cat_id','$isspecialoffer','$ov_title','$ov_period','$ov_bonus','$ov_highlight','$ov_notice','$da_depdates','$da_pricelabel','$da_extraprice','$da_pricetable','$tr_embassyid','$cityid','$short_title','$featured'
                    )";
        break;
    case 6: //prices
        if (isset($_SESSION['packageid']))
            $packageid = $_SESSION['packageid'];
        $type = $_REQUEST['type'];
        $curr = $_REQUEST['currency'];
        //$price = $_REQUEST['price'];
        $pricetext = $_REQUEST['pricetext'];
        
        $sql = "insert into $tablename(packageid,type,currency,pricetext) values('$packageid','$type','$curr','$pricetext')";
        break;
    case 7: //itinerary
        if (isset($_SESSION['packageid']))
            $packageid = $_SESSION['packageid'];
        $detail = $_REQUEST['detail'];
        
        $sql = "insert into ats_itinerary(packageid,detail) values('$packageid','$detail')";
        break;
    case 8: //users
        $username = $_REQUEST['username'];
        $password = $_REQUEST['password'];
        $email = $_REQUEST['email'];
        
        $sql = "insert into ats_users(username,password,email) values('$username',password('$password'),'$email')";
        break;
    case 10: //package category
        //no insert here
        break;
    case 11: //embassy
        $embassy = $_REQUEST['embassy'];
        $address = $_REQUEST['address'];
        $phone = $_REQUEST['phone'];
        $fax = $_REQUEST['fax'];
        $requirement = $_REQUEST['requirement'];
        $notes = $_REQUEST['notes'];
        $visaprices = $_REQUEST['visaprices'];
        
        $sql = "insert into ats_embassy(embassy,address,phone,fax,requirement,notes,visaprices) values('$embassy','$address','$phone','$fax','$requirement','$notes','$visaprices')";
        break;
    case 12:
        $tablabel = $_REQUEST['tablabel'];
        $address1 = $_REQUEST['address1'];
        $address2 = $_REQUEST['address2'];
        $region = $_REQUEST['region'];
        $city = $_REQUEST['city'];      
        $country = $_REQUEST['country'];
        $phone1 = $_REQUEST['phone1'];
        $phone2 = $_REQUEST['phone2'];
        $fax1 = $_REQUEST['fax'];
        $email = $_REQUEST['email'];
        
        $sql = "insert into ats_branch(tablabel,address1,address2,region,city,country,phone1,phone2,fax1,email) values('$tablabel','$address1','$address2','$region','$city','$country','$phone1','$phone2','$fax1','$email')";
        break;
    default:
        $firstname = $_REQUEST['firstname'];
        $lastname = $_REQUEST['lastname'];
        $phone = $_REQUEST['phone'];
        $email = $_REQUEST['email'];

        $sql = "insert into users(firstname,lastname,phone,email) values('$firstname','$lastname','$phone','$email')";
        
        //die(json_encode(array('msg' => $sql)));
        break;
}

$result = @mysql_query($sql);
if ($result) {
    echo json_encode(array('success' => true));
} else {
    echo json_encode(array('msg' => 'Some errors occured.'.$sql));
}
ob_end_flush();

?>